const express = require('express');
// const mysql = require('mysql');
var db = require('./config')
var app = express();
//中间件
app.use((req, res, next) => {
    res.header("Access-Control-Allow-Origin", "*"); // 或者指定特定的域名
    res.header("Access-Control-Allow-Headers", "Content-Type");
    next();
});
app.get('/xqo', function (req, res) {
    let sql = "SELECT * FROM users"
    db.query(sql, (err, result) => {
        console.log(result);

        if (err) {
            res.json({
                code: -1,
                msg: "查询失败",
            })
        } else {
            res.json({
                code: 200,
                msg: "查询成功",
                data: result,
            })
        }
    })
})

// 启动服务器
// const PORT = 3000;
app.listen(3000, () => {
    console.log('http://localhost:3000')
})